package com.pai4j.user.controller;
import com.pai4j.common.bean.PAIPageResponseBeanUtil;
import com.pai4j.common.bean.PAIResponseBean;
import com.pai4j.common.bean.PAIResponseBeanUtil;
import com.pai4j.domain.vo.request.request.payment.CreateAppRequestVO;
import com.pai4j.domain.vo.response.payment.AppBaseResponseVO;
import com.pai4j.domain.vo.response.payment.CreateAppResponseVO;
import com.pai4j.log.annotation.OperationLog;
import com.pai4j.remote.user.AccessApplicationServiceClient;
import com.pai4j.user.service.ApplicationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class AccessApplicationServiceController implements AccessApplicationServiceClient {


    @Autowired
    private ApplicationService accessApplicationService;

    @Override
    public PAIResponseBean<Boolean> checkAkSk(String ak, String sk) {
        boolean checkResult = accessApplicationService.validateAccessApplicationAkSk(ak, sk);
        return PAIResponseBeanUtil.success(checkResult);
    }

    @Override
    @OperationLog(
        module = "应用管理",
        operation = "创建应用",
        description = "创建新的支付应用",
        recordParams = true
    )
    public PAIResponseBean<CreateAppResponseVO> createApp(@RequestBody CreateAppRequestVO createAppRequest) {
        // TODO
        CreateAppResponseVO app = accessApplicationService.saveApp(createAppRequest);
        return PAIResponseBeanUtil.success(app);
    }

    @Override
    @OperationLog(
        module = "应用管理",
        operation = "发布应用",
        description = "发布支付应用",
        recordParams = true
    )
    public PAIResponseBean<Boolean> publishApp(@PathVariable Long appId) {
        accessApplicationService.publishApp(appId);
        return PAIResponseBeanUtil.success(true);
    }

    @Override
    @OperationLog(
        module = "应用管理",
        operation = "删除应用",
        description = "删除支付应用",
        recordParams = true
    )
    public PAIResponseBean<Boolean> deleteApp(@PathVariable Long appId) {
        accessApplicationService.deleteApp(appId);
        return PAIResponseBeanUtil.success(true);
    }

    @Override
    public PAIPageResponseBeanUtil<AppBaseResponseVO> page(String keywords, Integer pageNo, Integer pageSize) {

        return accessApplicationService.page(keywords, pageNo, pageSize);
    }
}
